package parent

import (
	"anban/controllers"
	"anban/models"
	"anban/service"
	"github.com/astaxie/beego"
	"html/template"
	"strconv"
)

type GradeNoticeController struct {
	controllers.BaseController
}

func (c *GradeNoticeController) ShowList() {
	c.Data["title"] = "成绩历史"
	c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
	c.TplName = "parent/grade-history.html"
}

func (c *GradeNoticeController) LoadMore() {
	count, _ := beego.AppConfig.Int("loadcount")
	curPage, _ := strconv.Atoi(c.GetString("p"))
	if curPage <= 0 {
		curPage = 1
	}

	userId := c.GetSession("userId")
	p := map[string]interface{}{}
	p["id"] = userId
	user := service.GetUserInfo(p)

	var studentIds []int64
	p = map[string]interface{}{}
	p["familySn"] = user.FamilySn
	_, studentList := service.GetStudentList(p)
	for _, student := range studentList {
		studentIds = append(studentIds, student.Id)
	}

	var gradeList []*models.GradeNotice
	if len(studentIds) > 0 {
		p = map[string]interface{}{}
		p["relation"] = true
		p["convert"] = true
		p["studentIds"] = studentIds
		p["curPage"] = curPage
		p["perCount"] = count
		_, gradeList = service.GetGradeNoticeList(p)
	}

	c.Data["gradeList"] = gradeList
	c.TplName = "parent/grade-history-list.html"
}
